package com.xy.home.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.xy.home.service.OrderHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 控制层： 用户首页显示
 */
@RestController
@RequestMapping("/order")
public class HomeOrderController extends BaseController {
    @Autowired
    private OrderHomeService orderHomeService;

    /**
     * 服务个数统计
     * @return
     */
    @GetMapping("/count")
    public AjaxResult count() {
        return success(orderHomeService.selectOrdersCount());
    }

    /**
     * 接单个数统计
     * @return
     */
    @GetMapping("/countByStatus")
    public AjaxResult countByStatus(Long status) {
        return success(orderHomeService.selectOrdersCountByStatus(status));
    }

    /**
     * 订单总额
     * @return
     */
    @GetMapping("/totalSales")
    public AjaxResult totalSales() {
        return success(orderHomeService.selectTotalSales());
    }

    /**
     * 获取平台月订单量数据
     * @return 包含月份和订单量数据的AjaxResult
     */
    @GetMapping("/monthlyOrders")
    public AjaxResult getMonthlyOrders() {
        return success(orderHomeService.selectMonthlyOrdersData());
    }


    /**
     * 获取平台最近七天订单量数据
     * @return 订单量数据列表的AjaxResult
     */
    @GetMapping("/recentDailyOrders")
    public TableDataInfo getRecentDailyOrders() {
        startPage();
        return getDataTable(orderHomeService.selectRecentDailyOrders());
    }

    /**
     * 获取平台订单支付方式分布数据
     * @return 支付方式分布数据列表的AjaxResult
     */
    @GetMapping("/paymentDistribution")
    public AjaxResult getPaymentMethodDistribution() {
        return success(orderHomeService.selectPaymentMethodDistribution());
    }

}
